package com.goldgov.mobile;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.authorityInfo.service.AuthorityInfoInit;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.kcloud.core.json.JsonSuccessObject;
import com.goldgov.learnmanage.service.User;
import com.goldgov.learnmanage.service.UserQuery;
import com.goldgov.learnmanage.service.UserService;
import com.goldgov.login.web.model.LoginAuthUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/mobile/myinformation")
@Api("个人信息移动接口")
public class MyInformationForMobileController {

	@Autowired
	private UserService userService;
	
	
	@GetMapping("/findMyCourseLearing")
	@ApiOperation(value = "我的学习情况", notes ="查询返回我的个人学习情况")
	public JsonSuccessObject<User> findMyCourseLearing(UserQuery query,HttpServletRequest request){
		LoginAuthUser u=LoginAuthUser.getUser(request);
	//	LoginAuthUser u=LoginAuthUser.getUserTest(request);
		if(query.getSearchOrgCode()==null||"".equals(query.getSearchOrgCode().trim())) {
			query.setSearchOrgCode(LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request));	
		}
		query.setSearchUserID(u.getEntityID());
		User user= userService.findMyCourseLearing(query);
		JsonSuccessObject<User> result = new JsonSuccessObject<User>(user);
		return result;
	}
	@GetMapping("/findOrgCourseLearing")
	@ApiOperation(value = "机构学习情况", notes ="查询机构用户学习情况")
	public JsonQueryObject<User>  findOrgCourseLearing(UserQuery query,HttpServletRequest request){
//		if (query.getSearchMember() == null) {
//			query.setSearchMember(UserQuery.ISMEMBER_YES);
//		}
		if(query.getSearchOrgCode()==null||"".equals(query.getSearchOrgCode().trim())) {
			query.setSearchOrgCode(LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request));	
		}
		List<User> list=userService.findOrgCourseLearing(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
}
